package com.chuanke.ckfamily.service.util;

import java.util.Random;

public class RedpacketUtil {

    private static Random random = new Random(System.currentTimeMillis());

    public static Long getRandonMoney(int num, Long money) {
        if (num == 1) {
            return money;

        } else {
            Double advPrice = (double)money / (double)num;
            Double randMaxPrice = advPrice * 2;

            if (randMaxPrice > (money - num + 1)) {
                randMaxPrice = (double)(money - num + 1);
            }

            randMaxPrice -= 1;
            if (randMaxPrice <= 0) {
                return 1l;

            } else {
                return new Long(random.nextInt(randMaxPrice.intValue()) + 1);

            }

        }
    }
}
